const {Service} = require('egg');

class UserService extends Service{
    //注册
    async registry(username,password,age){
        return await this.app.mysql.query('insert into userlist (username,password,age) values (?,?,?)',[username,password,age])
    }
    //查询
    async selectUser(username){
        return await this.app.mysql.query('select * from userlist where username=?',[username]);
    }
    //登录
    async login(username,password){
        return await this.app.mysql.query('select * from userlist where username=? and password=?',[username,password])
    }
    //注销
    async logout(id){
        return await this.app.mysql.query('delete from userlist where id=?',[id])
    }
    //判断密码是否一致
    async pwdSome(id,password){
        return await this.app.mysql.query('select * from userlist where id=? and password=?',[id,password])
    }
    //修改密码
    async editPassword(newPassword,id){
        return await this.app.mysql.query('update userlist set userlist.password=? where id=?',[newPassword,id])
    }

    //修改个人信息
    async editInfo(username,age,id){
        return await this.app.mysql.query('update userlist set userlist.username=?,age=? where id=?',[username,age,id])
    }
}

module.exports = UserService